1. Field of the Invention
The present invention relates generally to Virtual Machine (VM) technology and, more particularly, to methods and systems for optimization of transfers of control and segment operation in guest operating system code in VM.
2. Background Art
With VM technology, a user can create and run multiple operating environments on a computer at the same time. Each operating environment, or Virtual Machine, requires its own operating system (OS) and can run applications independently. The VM software provides a layer between the hardware of the computing system and the software that runs on it.
Frequently, the problem arises of simultaneously running different operating systems on the same hardware system. For example, with one version of MICROSOFT WINDOWS running on the computing system, it can be necessary to start another instance or another version of WINDOWS or another operating system on the same hardware system.
A typical Virtual Machine Monitor (VMM) enables a single physical machine or processor to act as if it were several physical machines. A VMM, typically jointly with a high-ranking OS (although there are VMMs that can be executed on bare hardware, without a high-ranking OS), can run a number of different operating systems simultaneously, such that each of the different operating systems has its own VM. In other words, a typical VMM can handle a number of VMs, each of which represents its own OS, and each of which can run its own application software and control or use its own hardware, including certain types of processors, I/O and data storage devices, and so on, as if they were running on a single processor. The high-ranking OS is typically referred to as a “host OS” (HOS). The multiple operating systems that are running as VMs are typically referred to as “guest operating systems” (“guest OSs”) running “guest code.”
A conventional approach for implementing VMs includes a VMM approach developed by IBM and implemented on mainframes, which support virtualization. Another approach includes implementing VMM on modern processors, which do not support the hardware virtualization, such as full step-by-step or page-by-page interpretation of the original code, or full binary translation of the original code, or combining binary translation of some portions of the original code and direct execution of other portions of the original code.
One of the common problems in Virtual Machine technology is the overhead that results from processing of privileged but unsafe instructions, also known as processing of “code under control.” In particular, in the context of many Virtual Machine implementations, such as, for example, described in U.S. patent application Ser. No. 11/139,787, entitled METHODS AND SYSTEMS FOR SAFE EXECUTION OF GUEST CODE IN VIRTUAL MACHINE CONTEXT, filed on May 31, 2005, which is incorporated herein by reference in its entirety, the high cost of the exceptions needed to handle the privileged but unsafe instructions is of particular concern. In other words, triggering, or raising, the exceptions is one of the major sources of overhead.
One of the problems that exist in emulation of code using Virtual Machine technology (sometimes known as the “code under control” technique) is the problem of overhead associated with execution of privileged but unsafe instructions. As a practical matter, the problem of privileged but unsafe instructions is primarily an issue with execution of guest operating system code, where such instructions are frequently present in large numbers. The user application code, even when emulated, rarely has a large number of privileged but unsafe instructions, since virtually all user application code is written by developers on the assumption that it is executed in a non-privileged mode (in the INTEL architecture example, Ring 3 level), and therefore the developer of the user application code knows that attempting to use privileged instructions in the user application would only trigger exceptions and errors.
However, the guest operating system is written on the assumption that it is running at the highest privileged level, or Ring 0 in the INTEL architecture. In other words, the guest operating system running in the Virtual Machine does not know that it is a guest operating system. Rather, it thinks that it is the “real” operating system. Therefore, there are frequently a significant number of privileged but unsafe instructions in the guest operating system code. These instructions need to be emulated, since the guest code cannot be permitted to execute instructions for which it, in reality, does not have a sufficient privilege level.
Therefore, the VM is forced to emulate these instructions using additional mechanisms, e.g., INT(n) (for the software debugger approach), and execution of the guest OS code raises frequent exceptions that require handling by the Virtual Machine Monitor, and requires emulation of those privileged but unsafe instructions. This is relatively overhead-intensive. Accordingly, there is a need in the art to reduce the amount of overhead associated with handling of guest operating system code during emulation.